<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品名称" prop="commodityName">
        <el-input v-model="queryParams.commodityName" placeholder="请输入产品名称" clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--    table表格区-->
    <el-table ref="singleTable" :data="productIntoList" highlight-current-row @current-change="handleCurrentChange"
              style="width: 100%"
    >
      <el-table-column label="产品名称" align="center" prop="commodityName"/>
      <el-table-column label="出品企业" align="center" prop="companyNameOut"/>
      <el-table-column label="采购企业" align="center" prop="companyNameInto"/>
      <el-table-column label="采购数量" align="center" prop="commodityNum"/>
      <el-table-column label="产品规格" align="center" prop="commoditySize">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.commodity_size" :value="scope.row.commoditySize"/>
        </template>
      </el-table-column>
      <el-table-column label="产品种类" align="center" prop="commodityType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.commodity_type" :value="scope.row.commodityType"/>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />
  </div>
</template>

<script>
import { listProductIntoPass } from '@/api/trace/productInto'

export default {
  name: 'ProductInto',
  dicts: ['commodity_type', 'commodity_status', 'commodity_size'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品采购详情表格数据
      productIntoList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        commodityOutId: null,
        commodityName: null,
        companyId: null,
        commodityNum: null,
        commodityUuid: null,
        staffId: null,
        commodityStaff: null,
        shipTime: null,
        checkId: null,
        checkStaff: null,
        checkTime: null,
        secturityCode: null,
        commodityStatus: null,
        companyNameInto: null,
        companyNameOut: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询商品采购详情列表 */
    getList() {
      this.loading = true
      listProductIntoPass(this.queryParams).then(response => {
        console.log(response)
        this.productIntoList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        commodityOutId: null,
        commodityName: null,
        companyId: null,
        commodityNum: null,
        commodityUuid: null,
        staffId: null,
        commodityStaff: null,
        shipTime: null,
        checkId: null,
        checkStaff: null,
        checkTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 单选选中时触发
    handleCurrentChange(currentRow) {
      console.log(currentRow)
      this.$emit('uploadIntoData', { id: currentRow.id, name: currentRow.companyNameInto })
    }
  }

}
</script>
